var app = {
    init: function() {
        api.setStatusBarStyle({
            style: 'light'
        });
    },
    signPrefix: 'kww_mall',
    sign: function(value) {
        // console.log(app.signPrefix + value)
        var base = new Base64();
        return base.encode(app.signPrefix + value);
    },
    getUser: function() {
        var user = api.getPrefs({
            sync: true,
            key: 'user'
        });
        return JSON.parse(user)
    },
    loadingFinish: function(Ve) {
        Ve.$nextTick(function() {
            Ve.loading = false
        })
    },
    host: 'http://mall.jxqkw8.com/index.php/api',
    request: {
        get: function(action, callback, options) {
            options = options || {}
            if (options.wait !== false) {
                api.showProgress({
                    title: '努力加载中...',
                    text: '先喝杯茶...',
                    modal: false
                });
            }

            api.ajax({
                url: app.host + action,
                method: 'get',
                headers: app.request.headers(),
            }, function(res, err) {
                api.hideProgress();
                if (res) {
                    callback(res);
                } else {
                    app.error(err.msg);
                }
            });
        },
        post: function(action, values, files, callback) {
            api.ajax({
                url: app.host + action,
                method: 'post',
                data: {
                    values: values,
                    files: files
                },
            }, function(res, err) {
                // api.hideProgress();
                if (res) {
                    callback(res);
                } else {
                    app.error(err.msg);
                }
            });
        }
    },
    error: function(msg) {
        api.toast({
            msg: msg,
            duration: 2000,
            location: 'top'
        });
    }
}
